import Vue from "vue";
// 导入router的模块
import VueRouter from "vue-router";

// 使用router插件
Vue.use(VueRouter);

// 导入需要使用路由切换的组件
import TestComponent from "@/components/test/TestComponent.vue";
import LoginComponent from "@/components/LoginComponent.vue";
import HomeComponent from "@/components/HomeComponent.vue";
import WelcomeComponent from "@/components/WelcomeComponent.vue";
import UserListComponent from "@/components/UserListComponent.vue";
import PasswordComponent from "@/components/PasswordComponent.vue";
import ArticleListComponent from "@/components/ArticleListComponent.vue";



// 创建路由的实例对象
const router = new VueRouter({
  // 定义路由匹配规则
  routes: [
    // redirect:访问path路径时(重定向)
    { path: "/", redirect: "/login" },
    { path: "/login", component: LoginComponent },
    {
      path: "/home",
      component: HomeComponent,
      children: [
        // redirect:访问path路径时(重定向)
        { path: "/", redirect: "welcomeComponent" },
        {
          path: "welcomeComponent",
          // 添加该字段，表示进入这个路由是需要登录的
          meta: {
            requireAuth: true,
          },
          component: WelcomeComponent,
        },
        {
          path: "admin/userListComponent",
          // 添加该字段，表示进入这个路由是需要登录的
          meta: {
            requireAuth: true,
          },
          component: UserListComponent,
        },
        {
          path: "admin/passwordComponent",
          // 添加该字段，表示进入这个路由是需要登录的
          meta: {
            requireAuth: true,
          },
          component: PasswordComponent,
        },
        {
          path: "blog/articleListComponent",
          // 添加该字段，表示进入这个路由是需要登录的
          meta: {
            requireAuth: true,
          },
          component: ArticleListComponent,
        },
      ],
    },
    {
      path: "/test",
      component: TestComponent,
      // 添加该字段，表示进入这个路由是不需要登录的
      meta: {
        requireAuth: false,
      },
    },
    // {
    //     path: '/about', component: AboutComponent,
    //     children:
    //         [
    //             // redirect:访问path路径时(重定向)
    //             { path: '/', redirect: 'tab1' },
    //             { path: 'tab1', component: AboutTab1Component },
    //             { path: 'tab2', component: AboutTab2Component },
    //         ]
    // },
    // // 动态路由
    // { path: '/movie/:id', component: MovieComponent, props: true }
  ],
});

// 向外共享路由的实例对象
export default router;
